package com.pignest.hotel.module.selfhelp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class SelfHelp {
	private static final String KEY_CURRENT = "self_help_current_member";
	private static final long EXPIRE = 60000 * 2;		//超时时间 2 分钟
	
	public static Current getCurrent(HttpServletRequest request, String cardSerial) {
		if (request == null)
			return null;
		HttpSession session = request.getSession();
		if (session == null)
			return null;
		Current current = (Current)session.getAttribute(KEY_CURRENT);
		if (current == null)
			return null;
		if (System.currentTimeMillis() - current.lastOperate > EXPIRE) {
			session.setAttribute(KEY_CURRENT, null);
			return null;
		}
		return current;
	}
	
	public static void release(HttpServletRequest request) {
		if (request == null)
			return;
		HttpSession session = request.getSession();
		if (session == null)
			return;
		session.setAttribute(KEY_CURRENT, null);
	}
}
